package kayao.server.threads;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Vector;

import kayao.common.KayaoValues;
import kayao.common.NetworkUtils;

public class NotYourKingThread extends Thread {

	private byte[]mData;
	private Vector<String> mAddresses;
	private DatagramSocket mSocket;
	public NotYourKingThread(Vector<String>ips,DatagramSocket s)
	{
		mSocket=s;
		mAddresses=ips;
		mData=new byte[9];
		byte []value=NetworkUtils.int32ToByte(KayaoValues.MAGIC_NUMBER);
		System.arraycopy(value, 0, mData, 0, 4);
		mData[4]=KayaoValues.SUSCRIPTION_REQUEST_NEGATIVE_ANSWER;
		NetworkUtils.insertIntToByteArray(mData, 5, 0);
	}
	public void run()
	{
		try
		{
			for(int i=0;i<mAddresses.size();i++)
			{
				System.out.println("[NotYourKingThread] - Sending to: "+ mAddresses.get(i));
				mSocket.send(new DatagramPacket(mData,mData.length,
						InetAddress.getByName(mAddresses.get(i)),KayaoValues.CLIENT_READ_PORT));
			}
		}
		catch(Exception e)
		{
			System.out.println("[NotYourKingThread] - Error sending.");
		}
		
	}
}
